﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using condortravel.operaciones.business.tour;
using condortravel.operaciones.entities.Entities;
using condortravel.operaciones.core.DataModel;
using condortravel.operaciones.common.Log;
using condortravel.operaciones.error.Operaciones;

namespace CondorTravelOperacionesWeb.Pages.Controles
{
    public partial class UCReporteTours : System.Web.UI.UserControl
    {

        private TourServices tourService;
        public TourServices TourServices
        {
            set { tourService = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void cmdBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                FilterTourCriteria filter = obtenerCriterios();
                List<Tb_Tour> lista = tourService.getReporteTour(filter);
                gvList.DataSource = lista;
                gvList.DataBind();

                if (lista.Count == 0)
                    throw new IncidentesException.NoExisteIncidenciasException();
            }
            catch (Exception exc1)
            {
                //this.ErrorControl(null, exc1);
                LogApp.WriteLog(ELogLevel.ERROR, string.Format("{0}-{1}", exc1.Message, exc1.StackTrace));
            }
        }

        private FilterTourCriteria obtenerCriterios()
        {
            FilterTourCriteria filter = new FilterTourCriteria();

            string dateIni =this.txtFechaInicio.Text;
            filter.Fecha_ini = Convert.ToDateTime(dateIni);

            string dateFin = this.txtFechaTermino.Text;
            filter.Fecha_fin = Convert.ToDateTime(dateFin);

            return filter;
        }
    }
}